www.gusucode.com > Augsburg Biosignal Toolbox源码程序 > matlab代做 修改 程序Augsburg Biosignal Toolbox/程序与说明/程序与说明/数据/Augsburg大学原始数据及说明/matlab/gui/AuBTgui.m

    function varargout = AuBTgui(varargin)
% AUBTGUI M-file for AuBTgui.fig
%      AUBTGUI, by itself, creates a new AUBTGUI or raises the existing
%      singleton*.
%
%      H = AUBTGUI returns the handle to a new AUBTGUI or the handle to
%      the existing singleton*.
%
%      EasyFeat('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in EasyFeat.M with the given input arguments.
%
%      EasyFeat('Property','Value',...) creates a new EasyFeat or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before EasyFeat_OpeningFunction gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to EasyFeat_OpeningFcn via varargin.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help EasyFeat

% Last Modified by GUIDE v2.5 14-Sep-2006 15:48:24

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @EasyFeat_OpeningFcn, ...
                   'gui_OutputFcn',  @EasyFeat_OutputFcn, ...
                   'gui_LayoutFcn',  [] , ...
                   'gui_Callback',   []);
if nargin && ischar(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT


% --- Executes just before EasyFeat is made visible.
function EasyFeat_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% varargin   command line arguments to EasyFeat (see VARARGIN)

% Choose default command line output for EasyFeat
handles.output = hObject;


% debuggin on/off
handles.debug = logical (varargin{1});

% root directory
handles.rpath = varargin{2};


% set global variables for feature extraction
handles.files = [];
handles.defaultSignalType = 5;
handles.signalType = handles.defaultSignalType;
                         % 1 = Sc
                         % 2 = Emg
                         % 3 = Rsp
                         % 4 = Ecg
                         % 5 = Other [default]
handles.signalTypeNames = strvcat ('Sc', 'Emg', 'Rsp', 'Ecg', 'Other');
handles.defaultSampleRate = 32;
handles.sampleRate = handles.defaultSampleRate; 
handles.blockGUI = logical (0);



% set global variables for feature combination
handles.featmat = [];
handles.featmatname = [];
handles.featnames = [];
handles.labels = [];
handles.labelnames = [];
handles.samplen = -1;



% set global variables for feature selection and classification
handles.selMethodNames = {'Anova', 'SFS', 'SBS'};
handles.selMethodFunc  = {'anova', 'sfs', 'sbs'};
handles.selMethodParams = {'0.05', '', ''};
handles.selMethodHelp = {'[p-value]', '[]', '[]'};
handles.classMethodNames = {'LDA', 'kNN (netlab)', 'MLP (netlab)'}; 
handles.classMethodFunc  = {'linear', 'knn', 'ffnet'};
handles.classMethodParams = {'', '3', '3 0.2 50'};
handles.classMethodHelp = {'[]', '[k-value]', '[layers alpha iter]'};
handles.redMethodNames = {'none', 'Fisher'};
handles.redMethodFunc  = {'none', 'fisher'};
handles.redMethodParams = {'', '2'};
handles.redMethodHelp = {'[]', '[dim]'};
handles.evalMethodNames = {'normal split', 'random split', 'one leave out'};
handles.evalMethodFunc  = {'normal-split', 'random-split', 'one-leave-out'};
handles.evalMethodParams = {'0.75', '0.75 10', ''};
handles.evalMethodHelp = {'[split]', '[split iter]', '[]'};
handles.selStratNames = {'all', 'best', 'break'};
handles.selStratFunc  = {'all', 'best', 'break'};
handles.selStratParams = {'', '', ''};
handles.selStratHelp = {'[<max>]', '[<max>]', '[<max>]'};



% adjust appearance
set (handles.EasyFeat_select_menu, 'String', handles.signalTypeNames);
set (handles.EasyFeat_select_menu, 'Value', handles.signalType);
set (handles.EasyFeat_samplerate_edit, 'String', num2str (handles.sampleRate));
set (handles.FeatSel_method_popup, 'String', char (handles.selMethodNames));
set (handles.Class_classifier_popup, 'String', char (handles.classMethodNames));
set (handles.Class_reduction_popup, 'String', char (handles.redMethodNames));
set (handles.Class_evaluation_popup, 'String', char (handles.evalMethodNames));
set (handles.FeatSel_strategy_popup, 'String', char (handles.selStratNames));
set (handles.EasyFeat_figure, 'CloseRequestFcn','closeAuBTguiFunc');
updateGUI (handles);

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes EasyFeat wait for user response (see UIRESUME)
% uiwait(handles.easyFeat_figure);


% --- Outputs from this function are returned to the command line.
function varargout = EasyFeat_OutputFcn(hObject, eventdata, handles) 
% varargout  cell array for returning output args (see VARARGOUT);
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure
varargout{1} = handles.output;








% --- Executes on button press in EasyFeat_openFile_button.
function EasyFeat_openFile_button_Callback(hObject, eventdata, handles)
% hObject    handle to EasyFeat_openFile_button (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% get filename
if handles.debug, disp ('get filename ...'); end
[filename filepath] = uigetfile ({'*.mat'});
if filename == 0
    if handles.debug, disp ('aborted'); end
    return;
end
filename = [filepath filename];
if handles.debug, disp ('ok'); end

% parse file
if handles.debug, disp ('parse file ...'); end
% fid = fopen (filename, 'r');
% filenum = 1;
% while 1
%     tline = fgetl(fid);
%     if ~ischar(tline)
%         break
%     end
% 	files{filenum} = strtrim (tline);
%     filenum = filenum + 1;
% end
% fclose (fid);
load (filename);
if ~exist ('files')
    FileCellArrayNotFoundError (filename);
    if handles.debug, disp ('error'); end
    return;
end
if ~exist ('hz')
    hz = handles.defaultSampleRate;
end
if exist ('name')
    sigind = strmatch (lower(strtrim(name)), lower(handles.signalTypeNames), 'exact');
    if isempty (sigind)
        sigind = handles.defautlSignalType;
    end
else
    sigind = handles.defaultSignalType;
end
if handles.debug, disp ('ok'); end

% check filenames
if handles.debug, disp ('check filenames ...'); end
for i = 1:length (files)
    if exist (files{i}) ~= 2
        if exist ([filepath files{i}]) ~= 2
            FileNotExistError (files{i});
            if handles.debug, disp ('error'); end
            return;
        else
            files{i} = [filepath files{i}];
        end
%         if handles.debug, disp (files{i}); end
    end
end
if handles.debug, disp ('ok'); end

% save files
if handles.debug, disp ('save files, samplerate and name ...'); end
handles.files = files;
handles.sampleRate = hz;
handles.signalType = sigind;
if handles.debug, disp ('ok'); end


% update gui data
if handles.debug, disp ('update gui'); end
set (handles.EasyFeat_select_text, 'String', [filename, ' (# ', num2str(length(files)), ')']);
set (handles.EasyFeat_samplerate_edit, 'String', num2str (handles.sampleRate));
set (handles.EasyFeat_select_menu, 'Value', sigind);
guidata (hObject, handles);
updateGUI (handles);
if handles.debug, disp ('ok'); end






% --- Executes on selection change in EasyFeat_select_menu.
function EasyFeat_select_menu_Callback(hObject, eventdata, handles)
% hObject    handle to EasyFeat_select_menu (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = get(hObject,'String') returns EasyFeat_select_menu contents as cell array
%        contents{get(hObject,'Value')} returns selected item from EasyFeat_select_menu

% get selected signal
if handles.debug, disp ('select signal'); end
handles.signalType = get (handles.EasyFeat_select_menu, 'Value');
if handles.debug, disp ('ok'); end

% update gui data
if handles.debug, disp ('update gui'); end
updateGUI (handles);
guidata (hObject, handles);
if handles.debug, disp ('ok'); end






% --- Executes during object creation, after setting all properties.
function EasyFeat_select_menu_CreateFcn(hObject, eventdata, handles)
% hObject    handle to EasyFeat_select_menu (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: popupmenu controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end






% --- Executes on button press in EasyFeat_extractStart_button.
function EasyFeat_extractStart_button_Callback(hObject, eventdata, handles)
% hObject    handle to EasyFeat_extractStart_button (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% check if feature seletion is already running and user wants to abort it
userdata = get (handles.EasyFeat_extractStart_button, 'UserData');
if ~isempty (userdata)
    set (handles.EasyFeat_extractStart_button, 'String', 'Abort', 'UserData', 1);
    return;
end

if handles.debug, disp ('update gui ...'); end
handles.blockGUI = logical (1);
updateGUI (handles);
% special gui actions
set (handles.EasyFeat_extractStart_button, 'String', 'Abort', 'Enable', 'on', 'UserData', 0);
drawnow;
if handles.debug, disp ('ok'); end

if handles.debug, disp ('prepare extraction ...'); end
featMatrix = [];
num = 0;
progress = 0;
fileNum = length (handles.files);
axes (handles.EasyFeat_extract_axes);
hold on;
axis ([0 1 0 1]);
h = fill ([0 1 1 0 0], [0 0 1 1 0], 'w');
set (gca, 'XTick',[],'YTick',[]);
drawnow;
if handles.debug, disp ('ok'); end

% get function
switch handles.signalType
    case 1 % Sc
        featExtractFunc = 'aubt_extractFeatSC (signal, handles.sampleRate)';
    case 2 % Emg
        featExtractFunc = 'aubt_extractFeatEMG (signal, handles.sampleRate)';
    case 3 % Rsp
        featExtractFunc = 'aubt_extractFeatRSP (signal, handles.sampleRate)';
    case 4 % Ecg
        featExtractFunc = 'aubt_extractFeatECG (signal, handles.sampleRate)';
    case 5 % User
        % get filename
        if handles.debug, disp ('get filename ...'); end
        [filename, filepath] = uigetfile('*.m');
        if filename == 0
            error ('aborted');
        end
        addpath (filepath);
        featExtractFunc = [filename(1:length(filename)-2) ' (signal, handles.sampleRate)'];
        if handles.debug, disp ('ok'); end
end

try
    for i = 1:fileNum

        % parse file
        if handles.debug, disp (['parse file ', handles.files{i}, ' ...']); end
        set (handles.EasyFeat_extractProgress_text, 'String', [handles.files{i}, ' (', num2str(i), '/', num2str(fileNum), ')']);
        drawnow;
        data = [];
        %     fid = fopen (handles.files{i}, 'r');
        %     while 1
        %         tline = fgetl(fid);
        %         if ~ischar(tline)
        %             break
        %         end
        %         data = [data; str2num(tline)];
        %     end
        %     fclose (fid);
        signal = [];
        try
            load (handles.files{i}, '-mat');
        catch
        end
        if isempty (signal)
            SignalVectorNotFoundError (handles.files{i})
            error ('signal vector not found');
        end
        if handles.debug, disp ('ok'); end

        % feature extraction
        if handles.debug, disp ('extract features ...'); end
        [featVec, featNames] = eval (featExtractFunc);        
        
        % save feature vector
        if isempty (featMatrix), featMatrix = zeros (fileNum, length (featVec)); end
        featMatrix(i,:) = featVec;
        
       	% check if aborted by user
        drawnow;
        userdata = get (handles.EasyFeat_extractStart_button, 'UserData');
        if userdata == 1
            featMatrix = [];
            error ('aborted');
        end
        
        % addjust progress bar
        progress = i / fileNum;
        axes (handles.EasyFeat_extract_axes);
        axis ([0 1 0 1]);
        fill ([0 progress progress 0 0], [0 0 1 1 0], 'b');
        set (gca, 'XTick',[],'YTick',[]);
        drawnow;
        if handles.debug, disp ('ok'); end
    end
    hold off;
    set (handles.EasyFeat_extractProgress_text, 'String', 'Done');
    
    % remove feature columns if values not change
    if handles.debug, disp ('check features ...'); end
    remFeats = [];
    for i = 1:size(featMatrix,2)
        if min (featMatrix(:,i)) == max (featMatrix(:,i))
            remFeats = [remFeats, i];
        end
    end
    featMatrix(:,remFeats) = [];
    featNames(remFeats) = [];
    if handles.debug, disp (['ok (', num2str(length(remFeats)), ' removed)']); end
        
    % save features
    if handles.debug, disp ('add features ...'); end
    if handles.samplen == -1
        handles.samplen = size (featMatrix, 1);
    elseif handles.samplen ~= size (featMatrix, 1)
        WrongSampleNumberError (size (featMatrix, 1), handles.samplen);
        % update gui data
        error ('failed (wrong sample number)');
    end
    num = length (handles.featmat) + 1;
    handles.featmat{num} = featMatrix;
    sigNames = get (handles.EasyFeat_select_menu, 'String');
    handles.featmatname{num} = [strtrim(sigNames(handles.signalType,:)), ' (# ', num2str(size (featMatrix)), ')'];
    handles.featnames{num} = char (featNames);
    set (handles.combiFeat_signals_listbox, 'String', char (handles.featmatname), 'Value', num)
    if handles.debug, disp ('done'); end
catch    
    if handles.debug, err = lasterror(); err.message, end
end

% update gui data
if handles.debug, disp ('update gui ...'); end
handles.blockGUI = logical (0);
set (handles.EasyFeat_extractStart_button, 'String', 'Run', 'Enable', 'on', 'UserData', []);
guidata (hObject, handles);
updateGUI (handles);
if handles.debug, disp ('ok'); end







function EasyFeat_samplerate_edit_Callback(hObject, eventdata, handles)
% hObject    handle to EasyFeat_samplerate_edit (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of EasyFeat_samplerate_edit as text
%        str2double(get(hObject,'String')) returns contents of EasyFeat_samplerate_edit as a double

if handles.debug, disp ('change samplerate ...'); end
sampleRate = get (hObject, 'String');
handles.sampleRate = str2num (sampleRate);
guidata(hObject, handles);
if handles.debug, disp ('ok'); end

% --- Executes during object creation, after setting all properties.
function EasyFeat_samplerate_edit_CreateFcn(hObject, eventdata, handles)
% hObject    handle to EasyFeat_samplerate_edit (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end





% --- Executes on button press in combiFeat_combiFeat_button.
function combiFeat_exportArff_button_Callback(hObject, eventdata, handles)
% hObject    handle to combiFeat_combiFeat_button (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

if isempty (handles.labels)
    NoLabelFileLoadedError ();
    return;
end

if isempty (handles.featmat)
    NoFeatureFileLoadedError ();
    return;
end

% get filename
if handles.debug, disp ('get filename ...'); end
[filename_, filepath] = uiputfile('*.arff');
if filename_ == 0
    if handles.debug, disp ('aborted'); end
    return;
end
filename = [filepath filename_];
if handles.debug, disp ('ok'); end

if handles.debug, disp ('export arff file ...'); end
num = length (handles.featmat);
featmat = [];
featnames = [];
for i = 1:num
    featmat = [featmat, handles.featmat{i}];
    featnames = strvcat (featnames, handles.featnames{i});
end
labels = handles.labels;
labelnames = handles.labelnames;
fset = str2num (get (handles.FeatSel_select_edit, 'String'));
fset (find (fset < 1 | fset > size (featmat, 2))) = [];
   
if ~ isempty (fset)
    answer = questdlg ('Export only selected features?','Question','Yes','No','No');
    if strcmp (answer, 'Yes')
        featmat = featmat(:,fset);
        featnames = featnames(fset,:);
    end
end
aubt_export2arff (featmat, labels, featnames, labelnames, filename_);
if handles.debug, disp ('ok'); end






% --- Executes on button press in combiFeat_label_button.
function combiFeat_label_button_Callback(hObject, eventdata, handles)
% hObject    handle to combiFeat_label_button (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% select file
filename = 0;
[filename, filepath] = uigetfile ('*.mat','Select the mat-file');
if isequal (filename, 0)
    return;
end

% load labels
if handles.debug; disp (['load label file ', [filepath, filename], ' ... ']); end
data = load ([filepath, filename]);
if ~ isfield (data, 'labels')
    if handles.debug; disp ('failed (missing field ''labels'')'); end
    MissingLabelFieldError;
    return;
end
if ~ isfield (data, 'labelnames')
    if handles.debug; disp ('failed (missing field ''labelnames'')'); end
    MissingLabelnamesFieldError;
    return;
end
if handles.debug; disp ('ok'); end

% add labels
if handles.debug; disp ('add labels ...'); end
if handles.samplen == -1 | isempty (handles.featmat)
    handles.samplen = length (data.labels);
elseif handles.samplen ~= length (data.labels)
    WrongSampleNumberError2 (length (data.labels), handles.samplen);
    if handles.debug, disp ('failed (wrong label number)'); end
    return;
end
handles.labels = data.labels;
handles.labelnames = data.labelnames;
set (handles.combiFeat_label_text, 'String', [filepath, filename, ' (# ', num2str(handles.samplen), ')'])
if handles.debug; disp ('ok'); end

% update gui
if handles.debug; disp ('update gui ...'); end
guidata(hObject, handles);
updateGUI (handles);
if handles.debug; disp ('ok'); end






% --- Executes on button press in combiFeat_signals_add_button.
function combiFeat_signals_add_button_Callback(hObject, eventdata, handles)
% hObject    handle to combiFeat_signals_add_button (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% select file
filename = 0;
[filename, filepath] = uigetfile ('*.mat','Select the mat-file');
if isequal (filename, 0)
    return;
end

% load signal data
if handles.debug; disp (['load feature file', [filepath, filename], ' ... ']); end
data = load ([filepath, filename]);
if ~ isfield (data, 'featmat')
    if handles.debug; disp ('failed (missing field ''featmat'')'); end
    MissingFeatmatFieldError;
    return;
end
if ~ isfield (data, 'featnames')
    if handles.debug; disp ('failed (missing field ''featnames'')'); end
    MissingFeatnamesFieldError;
    return;
end
if handles.debug; disp ('ok'); end

if handles.debug; disp (['add features ... ']); end
if handles.samplen == -1
    handles.samplen = size (data.featmat, 1);
elseif handles.samplen ~= size (data.featmat, 1)
    WrongSampleNumberError (size (data.featmat, 1), handles.samplen);
    if handles.debug, disp ('failed (wrong sample number)'); end
	return;
end
num = length (handles.featmat) + 1;
handles.featmat{num} = data.featmat;
handles.featmatname{num} = [filename, ' (# ', num2str(size (data.featmat)), ')'];
handles.featnames{num} = data.featnames;
if handles.debug; disp ('ok'); end

% update gui
if handles.debug; disp ('update gui ...'); end
set (handles.combiFeat_signals_listbox, 'String', char (handles.featmatname), 'Value', num);
guidata (hObject, handles);
updateGUI (handles);
if handles.debug; disp ('ok'); end







% --- Executes on button press in combiFeat_signals_remove_button.
function combiFeat_signals_remove_button_Callback(hObject, eventdata, handles)
% hObject    handle to combiFeat_signals_remove_button (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

if handles.debug, disp ('remove selected signal ...'); end
selNum = get (handles.combiFeat_signals_listbox, 'Value');
handles.featmat(selNum) = [];
handles.featmatname(selNum) = [];
handles.featnames(selNum) = [];
if handles.debug, disp ('ok'); end

% update gui
if handles.debug, disp ('update gui ...'); end
set (handles.combiFeat_signals_listbox, 'String', char (handles.featmatname), 'Value', 1)
guidata (hObject, handles);
updateGUI (handles);
if handles.debug, disp ('ok'); end







% --- Executes on selection change in combiFeat_signals_listbox.
function combiFeat_signals_listbox_Callback(hObject, eventdata, handles)
% hObject    handle to combiFeat_signals_listbox (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = get(hObject,'String') returns combiFeat_signals_listbox contents as cell array
%        contents{get(hObject,'Value')} returns selected item from combiFeat_signals_listbox

% --- Executes during object creation, after setting all properties.
function combiFeat_signals_listbox_CreateFcn(hObject, eventdata, handles)
% hObject    handle to combiFeat_signals_listbox (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: listbox controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end




% --- Executes on button press in combiFeat_exportMat_button.
function combiFeat_exportMat_button_Callback(hObject, eventdata, handles)
% hObject    handle to combiFeat_exportMat_button (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

if isempty (handles.labels)
    NoLabelFileLoadedError ();
    return;
end

if isempty (handles.featmat)
    NoFeatureFileLoadedError ();
    return;
end

% get filename
if handles.debug, disp ('get filename ...'); end
[filename_, filepath] = uiputfile('*.mat');
if filename_ == 0
    if handles.debug, disp ('aborted'); end
    return;
end
filename = [filepath filename_];
if handles.debug, disp ('ok'); end

if handles.debug, disp ('export mat file ...'); end
num = length (handles.featmat);
featmat = [];
featnames = [];
for i = 1:num
    featmat = [featmat, handles.featmat{i}];
    featnames = strvcat (featnames, handles.featnames{i});
end
labels = handles.labels;
labelnames = handles.labelnames;
fset = str2num (get (handles.FeatSel_select_edit, 'String'));
if ~ isempty (fset)
    answer = questdlg ('Export only selected features?','Question','Yes','No','No');
    if strcmp (answer, 'Yes')
        featmat = featmat(:,fset);
        featnames = featnames(fset,:);
    end
end
save (filename, 'featmat', 'labels', 'featnames', 'labelnames');
if handles.debug, disp ('ok'); end






function FeatSel_select_edit_Callback(hObject, eventdata, handles)
% hObject    handle to FeatSel_select_edit (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of FeatSel_select_edit as text
%        str2double(get(hObject,'String')) returns contents of FeatSel_select_edit as a double


% --- Executes during object creation, after setting all properties.
function FeatSel_select_edit_CreateFcn(hObject, eventdata, handles)
% hObject    handle to FeatSel_select_edit (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on button press in FeatSel_clear_button.
function FeatSel_clear_button_Callback(hObject, eventdata, handles)
% hObject    handle to FeatSel_clear_button (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

if handles.debug, disp ('clear feature selection ...'); end
set (handles.FeatSel_select_edit, 'String', '');
if handles.debug, disp ('ok'); end


% --- Executes on selection change in FeatSel_methodHelp_text_popup.
function FeatSel_method_popup_Callback(hObject, eventdata, handles)
% hObject    handle to FeatSel_methodHelp_text_popup (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = get(hObject,'String') returns FeatSel_methodHelp_text_popup contents as cell array
%        contents{get(hObject,'Value')} returns selected item from FeatSel_methodHelp_text_popup

if handles.debug, disp ('update gui ...'); end
updateGUI (handles);
if handles.debug, disp ('ok'); end

% --- Executes during object creation, after setting all properties.
function FeatSel_method_popup_CreateFcn(hObject, eventdata, handles)
% hObject    handle to FeatSel_methodHelp_text_popup (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: popupmenu controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on selection change in Class_classifier_popup.
function Class_classifier_popup_Callback(hObject, eventdata, handles)
% hObject    handle to Class_classifier_popup (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = get(hObject,'String') returns Class_classifier_popup contents as cell array
%        contents{get(hObject,'Value')} returns selected item from Class_classifier_popup

if handles.debug, disp ('update gui ...'); end
updateGUI (handles);
if handles.debug, disp ('ok'); end


% --- Executes during object creation, after setting all properties.
function Class_classifier_popup_CreateFcn(hObject, eventdata, handles)
% hObject    handle to Class_classifier_popup (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: popupmenu controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on selection change in Class_reduction_popup.
function Class_reduction_popup_Callback(hObject, eventdata, handles)
% hObject    handle to Class_reduction_popup (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = get(hObject,'String') returns Class_reduction_popup contents as cell array
%        contents{get(hObject,'Value')} returns selected item from Class_reduction_popup

if handles.debug, disp ('update gui ...'); end
updateGUI (handles);
if handles.debug, disp ('ok'); end


% --- Executes during object creation, after setting all properties.
function Class_reduction_popup_CreateFcn(hObject, eventdata, handles)
% hObject    handle to Class_reduction_popup (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: popupmenu controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on selection change in Class_evaluation_popup.
function Class_evaluation_popup_Callback(hObject, eventdata, handles)
% hObject    handle to Class_evaluation_popup (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = get(hObject,'String') returns Class_evaluation_popup contents as cell array
%        contents{get(hObject,'Value')} returns selected item from Class_evaluation_popup

if handles.debug, disp ('update gui ...'); end
updateGUI (handles);
if handles.debug, disp ('ok'); end


% --- Executes during object creation, after setting all properties.
function Class_evaluation_popup_CreateFcn(hObject, eventdata, handles)
% hObject    handle to Class_evaluation_popup (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: popupmenu controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on selection change in FeatSel_strategy_popup.
function FeatSel_strategy_popup_Callback(hObject, eventdata, handles)
% hObject    handle to FeatSel_strategy_popup (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = get(hObject,'String') returns FeatSel_strategy_popup contents as cell array
%        contents{get(hObject,'Value')} returns selected item from FeatSel_strategy_popup

if handles.debug, disp ('update gui ...'); end
updateGUI (handles);
if handles.debug, disp ('ok'); end


% --- Executes during object creation, after setting all properties.
function FeatSel_strategy_popup_CreateFcn(hObject, eventdata, handles)
% hObject    handle to FeatSel_strategy_popup (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: popupmenu controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end









% --- update gui appearance
function updateGUI (handles)

% set mouse pointer
if handles.blockGUI
    set (handles.EasyFeat_figure, 'Pointer', 'watch');
    set (handles.AuBTgui_about_button, 'Enable', 'off');
%     set (handles.AuBTgui_help_button, 'Enable', 'off');
    set (handles.AuBTgui_exit_button, 'Enable', 'off');    
else
    set (handles.EasyFeat_figure, 'Pointer', 'arrow');
    set (handles.AuBTgui_about_button, 'Enable', 'on');
%     set (handles.AuBTgui_help_button, 'Enable', 'on');
    set (handles.AuBTgui_exit_button, 'Enable', 'on');        
end

% determine state
if handles.blockGUI
    easyFeatState = 2;
elseif isempty (handles.files)
    easyFeatState = 0;
else
    easyFeatState = 1; 
end

switch easyFeatState
    case 0 % files or signal not selected        
        set (handles.EasyFeat_openFile_button, 'Enable', 'on');
        set (handles.EasyFeat_select_menu, 'Enable', 'on');
        set (handles.EasyFeat_extractStart_button, 'Enable', 'off');               
        set (handles.EasyFeat_samplerate_edit, 'Enable', 'on');
    case 1 % files and signal selected
        set (handles.EasyFeat_openFile_button, 'Enable', 'on');
        set (handles.EasyFeat_select_menu, 'Enable', 'on');
        set (handles.EasyFeat_extractStart_button, 'Enable', 'on');  
        set (handles.EasyFeat_samplerate_edit, 'Enable', 'on');    
    case 2 % all disabled
        set (handles.EasyFeat_openFile_button, 'Enable', 'off');
        set (handles.EasyFeat_select_menu, 'Enable', 'off');
        set (handles.EasyFeat_extractStart_button, 'Enable', 'off');
        set (handles.EasyFeat_samplerate_edit, 'Enable', 'off');       
end

% determine state
if handles.blockGUI
    combiFeatState = 4;
elseif isempty (handles.labels) & isempty (handles.featmat)
    combiFeatState = 0;
elseif isempty (handles.featmat)
    combiFeatState = 1;
elseif isempty (handles.labels)
    combiFeatState = 2; 
else
    combiFeatState = 3; 
end

switch combiFeatState
    case 0 % labels and signals not selected
        set (handles.combiFeat_label_button, 'Enable', 'on');
        set (handles.combiFeat_signals_add_button, 'Enable', 'on');
        set (handles.combiFeat_signals_remove_button, 'Enable', 'off');
        set (handles.combiFeat_exportMat_button, 'Enable', 'off');
        set (handles.combiFeat_exportArff_button, 'Enable', 'off');
        set (handles.combiFeat_fisherPlot_button, 'Enable', 'off');        
    case 1 % only labels selected
        set (handles.combiFeat_label_button, 'Enable', 'on');
        set (handles.combiFeat_signals_add_button, 'Enable', 'on');
        set (handles.combiFeat_signals_remove_button, 'Enable', 'off');
        set (handles.combiFeat_exportMat_button, 'Enable', 'off');
        set (handles.combiFeat_exportArff_button, 'Enable', 'off');
        set (handles.combiFeat_fisherPlot_button, 'Enable', 'off');                
    case 2 % only signals selected
        set (handles.combiFeat_label_button, 'Enable', 'on');
        set (handles.combiFeat_signals_add_button, 'Enable', 'on');
        set (handles.combiFeat_signals_remove_button, 'Enable', 'on');
        set (handles.combiFeat_exportMat_button, 'Enable', 'off');
        set (handles.combiFeat_exportArff_button, 'Enable', 'off');
        set (handles.combiFeat_fisherPlot_button, 'Enable', 'off');                
    case 3 % labels and signals selected
        set (handles.combiFeat_label_button, 'Enable', 'on');
        set (handles.combiFeat_signals_add_button, 'Enable', 'on');
        set (handles.combiFeat_signals_remove_button, 'Enable', 'on');
        set (handles.combiFeat_exportMat_button, 'Enable', 'on');
        set (handles.combiFeat_exportArff_button, 'Enable', 'on');
        set (handles.combiFeat_fisherPlot_button, 'Enable', 'on');                
    case 4 % all disabled
        set (handles.combiFeat_label_button, 'Enable', 'off');
        set (handles.combiFeat_signals_add_button, 'Enable', 'off');
        set (handles.combiFeat_signals_remove_button, 'Enable', 'off');
        set (handles.combiFeat_exportMat_button, 'Enable', 'off');
        set (handles.combiFeat_exportArff_button, 'Enable', 'off');
        set (handles.combiFeat_fisherPlot_button, 'Enable', 'off');        
end

% determine state of feature selection
selMethod = get (handles.FeatSel_method_popup, 'Value');
if handles.blockGUI | isempty (handles.labels) | isempty (handles.featmat)
    selFeatState = 2;
elseif selMethod == 1
    selFeatState = 0;
else
    selFeatState = 1;
end

switch selFeatState
    case 0 % anova selected
        set (handles.FeatSel_method_popup, 'Enable', 'on');
        set (handles.FeatSel_strategy_popup, 'Enable', 'off');
        set (handles.FeatSel_methodParams_edit, 'Enable', 'on');
        set (handles.FeatSel_strategyParams_edit, 'Enable', 'off');     
        set (handles.FeatSel_run_button, 'Enable', 'on');
        set (handles.FeatSel_select_edit, 'Enable', 'on');
        set (handles.FeatSel_clear_button, 'Enable', 'on');
        set (handles.FeatSel_boxplot_button, 'Enable', 'on');
        set (handles.FeatSel_methodHelp_text, 'Enable', 'on');   
        ind = get (handles.FeatSel_method_popup, 'Value');
        set (handles.FeatSel_methodParams_edit, 'String', handles.selMethodParams{ind});
        set (handles.FeatSel_methodHelp_text, 'String', handles.selMethodHelp{ind});      
        set (handles.FeatSel_strategyHelp_text, 'Enable', 'off');        
    case 1 % anova not selected
        set (handles.FeatSel_method_popup, 'Enable', 'on');
        set (handles.FeatSel_strategy_popup, 'Enable', 'on');
        set (handles.FeatSel_strategyParams_edit, 'Enable', 'on');       
        set (handles.FeatSel_methodParams_edit, 'Enable', 'on');
        set (handles.FeatSel_run_button, 'Enable', 'on');
        set (handles.FeatSel_select_edit, 'Enable', 'on');
        set (handles.FeatSel_clear_button, 'Enable', 'on');
        set (handles.FeatSel_boxplot_button, 'Enable', 'on');     
        set (handles.FeatSel_methodHelp_text, 'Enable', 'on');  
        ind = get (handles.FeatSel_method_popup, 'Value');
        set (handles.FeatSel_methodParams_edit, 'String', handles.selMethodParams{ind});
        set (handles.FeatSel_methodHelp_text, 'String', handles.selMethodHelp{ind});           
        set (handles.FeatSel_strategyHelp_text, 'Enable', 'on');          
        ind = get (handles.FeatSel_strategy_popup, 'Value');
        set (handles.FeatSel_strategyParams_edit, 'String', handles.selStratParams{ind});
        set (handles.FeatSel_strategyHelp_text, 'String', handles.selStratHelp{ind});            
    case 2 % no features calculated yet
        set (handles.FeatSel_method_popup, 'Enable', 'off');
        set (handles.FeatSel_strategy_popup, 'Enable', 'off');
        set (handles.FeatSel_methodParams_edit, 'Enable', 'off');
        set (handles.FeatSel_strategyParams_edit, 'Enable', 'off');             
        set (handles.FeatSel_run_button, 'Enable', 'off');
        set (handles.FeatSel_select_edit, 'Enable', 'off');
        set (handles.FeatSel_clear_button, 'Enable', 'off');
        set (handles.FeatSel_boxplot_button, 'Enable', 'off');   
        set (handles.FeatSel_methodHelp_text, 'Enable', 'off');                  
        set (handles.FeatSel_strategyHelp_text, 'Enable', 'off');         
end


% determine state of classification
if handles.blockGUI | isempty (handles.labels) | isempty (handles.featmat)
    classState = 1;
else
    classState = 0;
end

switch classState
    case 0
        set (handles.Class_classifier_popup, 'Enable', 'on');
        set (handles.Class_reduction_popup, 'Enable', 'on');
        set (handles.Class_evaluation_popup, 'Enable', 'on');
        set (handles.Class_classifierParams_edit, 'Enable', 'on');
        set (handles.Class_reductionParams_edit, 'Enable', 'on');
        set (handles.Class_evaluationParams_edit, 'Enable', 'on');
        set (handles.Class_classifierHelp_text, 'Enable', 'on');   
        ind = get (handles.Class_classifier_popup, 'Value');
        set (handles.Class_classifierParams_edit, 'String', handles.classMethodParams{ind});
        set (handles.Class_classifierHelp_text, 'String', handles.classMethodHelp{ind});    
        set (handles.Class_reductionHelp_text, 'Enable', 'on');        
        ind = get (handles.Class_reduction_popup, 'Value');
        set (handles.Class_reductionParams_edit, 'String', handles.redMethodParams{ind});
        set (handles.Class_reductionHelp_text, 'String', handles.redMethodHelp{ind});            
        set (handles.Class_evaluationHelp_text, 'Enable', 'on');        
        ind = get (handles.Class_evaluation_popup, 'Value');
        set (handles.Class_evaluationParams_edit, 'String', handles.evalMethodParams{ind});
        set (handles.Class_evaluationHelp_text, 'String', handles.evalMethodHelp{ind});   
        set (handles.Class_run_button, 'Enable', 'on');      
    case 1
        set (handles.Class_classifier_popup, 'Enable', 'off');
        set (handles.Class_reduction_popup, 'Enable', 'off');
        set (handles.Class_evaluation_popup, 'Enable', 'off');
        set (handles.Class_classifierParams_edit, 'Enable', 'off');
        set (handles.Class_reductionParams_edit, 'Enable', 'off');
        set (handles.Class_evaluationParams_edit, 'Enable', 'off');         
        set (handles.Class_classifierHelp_text, 'Enable', 'off');   
        set (handles.Class_reductionHelp_text, 'Enable', 'off');        
        set (handles.Class_evaluationHelp_text, 'Enable', 'off');              
        set (handles.Class_run_button, 'Enable', 'off');
end


% error messages
function Error ()
msgbox ('An error occured', 'Error', 'error');

function FileNotExistError (filename)
msgbox (['File ', filename, ' was not found.'], 'Error', 'error');

function FileCellArrayNotFoundError (filename)
msgbox (['Cell array ''files'' with filenames not found in ', filename, '.'], 'Error', 'error');

function SignalVectorNotFoundError (filename)
msgbox (['Vector ''signal'' with signal values not found in ', filename, '.'], 'Error', 'error');

function NoFeatureFileLoadedError ()
msgbox (['No feature file loaded yet.'], 'Error', 'error');

function NoLabelFileLoadedError ()
msgbox (['Label file not loaded yet.'], 'Error', 'error');

function MissingLabelFieldError ()
msgbox (['Could not add labels: field ''labels'' not found.'], 'Error', 'error');

function MissingLabelnamesFieldError ()
msgbox (['Could not add labels: field ''labelnames'' not found.'], 'Error', 'error');

function MissingFeatmatFieldError ()
msgbox (['Could not add labels: field ''featmat'' not found.'], 'Error', 'error');

function MissingFeatnamesFieldError ()
msgbox (['Could not add labels: field ''featnames'' not found.'], 'Error', 'error');

function WrongSampleNumberError2 (foundNum, expectedNum)
msgbox (['Could not add labels: expected ', num2str(expectedNum), ' labels but ', num2str(foundNum), ' were found.'], 'Error', 'error');

function WrongSampleNumberError (foundNum, expectedNum)
msgbox (['Could not add features: expected ', num2str(expectedNum), ' samples but ', num2str(foundNum), ' were found.'], 'Error', 'error');




% --- Executes on button press in FeatSel_run_button.
function FeatSel_run_button_Callback(hObject, eventdata, handles)
% hObject    handle to FeatSel_run_button (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% check if feature seletion is already running and user wants to abort it
userdata = get (handles.FeatSel_run_button, 'UserData');
if ~isempty (userdata)
    set (handles.FeatSel_run_button, 'String', 'Abort', 'UserData', 1);
    return;
end

if handles.debug, disp ('update gui ...'); end
handles.blockGUI = logical (1);
updateGUI (handles);
% special gui actions
set (handles.FeatSel_run_button, 'String', 'Abort', 'Enable', 'on', 'UserData', 0);
set (handles.FeatSel_progress_text, 'String', 'Feature selection running ...');
drawnow;
if handles.debug, disp ('ok'); end

if handles.debug, disp ('prepare feature selection ...'); end
selMethod = get (handles.FeatSel_method_popup, 'Value');
sopt = str2num (get (handles.FeatSel_methodParams_edit, 'String'));
cmethod = handles.classMethodFunc{get (handles.Class_classifier_popup, 'Value')};
copt = str2num (get (handles.Class_classifierParams_edit, 'String'));
rmethod = handles.redMethodFunc{get (handles.Class_reduction_popup, 'Value')};
ropt = str2num (get (handles.Class_reductionParams_edit, 'String'));
emethod = handles.evalMethodFunc{get (handles.Class_evaluation_popup, 'Value')};
eopt = str2num (get (handles.Class_evaluationParams_edit, 'String'));
smethod = handles.selStratFunc{get (handles.FeatSel_strategy_popup, 'Value')};
k = str2num (get (handles.FeatSel_strategyParams_edit, 'String'));
num = length (handles.featmat);
featmat = [];
for i = 1:num
    featmat = [featmat, handles.featmat{i}];
end
labels = handles.labels;
fsetold = str2num (get (handles.FeatSel_select_edit, 'String'));
fsetold (find (fsetold < 1 | fsetold > size (featmat, 2))) = [];
if isempty (fsetold)
    fsetold = 1:size (featmat, 2);
end
featmat = featmat(:,fsetold);
if handles.debug, disp ('ok'); end

try
    switch selMethod
        case 1 % anova
            if handles.debug, disp ('run feature selection ...');
                sprintf ('method: Anova [%s]', num2str(sopt))
            end
            p = aubt_anova_gui (featmat, labels, handles.FeatSel_extract_axes, handles.FeatSel_run_button);
            fset = find (p <= sopt);
        case 2 % sfs
            if handles.debug, disp ('run feature selection ...');
                sprintf ('method: SFS [%s]\nclassifier: %s [%s]\nreduction: %s [%s]\nevaluation: %s [%s]\nstrategy: %s [%s]', ...
                    num2str(sopt), cmethod, num2str(copt), rmethod, num2str(ropt), emethod, num2str(eopt), smethod, num2str(k))
            end
            fset = aubt_sfs_gui (handles.FeatSel_extract_axes, handles.FeatSel_run_button, featmat, labels, cmethod, copt, rmethod, ropt, emethod, eopt, smethod, k);
        case 3 % sbs
            if handles.debug, disp ('run feature selection ...');
                sprintf ('method: SBS [%s]\nclassifier: %s [%s]\nreduction: %s [%s]\nevaluation: %s [%s]\nstrategy: %s [%s]', ...
                    num2str(sopt), cmethod, num2str(copt), rmethod, num2str(ropt), emethod, num2str(eopt), smethod, num2str(k))
            end
            fset = aubt_sbs_gui (handles.FeatSel_extract_axes, handles.FeatSel_run_button, featmat, labels, cmethod, copt, rmethod, ropt, emethod, eopt, smethod, k);
    end
    fset = fsetold(fset);
    if handles.debug, disp ('ok'); end
catch
    fset = [];
    if handles.debug, err = lasterror(); err.message, end
    Error ();
end
    
if handles.debug, disp ('update gui ...'); end
handles.blockGUI = logical (0);
if ~isempty (fset)
    set (handles.FeatSel_run_button, 'String', 'Run', 'Enable', 'on', 'UserData', []);
    set (handles.FeatSel_select_edit, 'String', num2str (fset));
    set (handles.FeatSel_progress_text, 'String', 'Done');
else
    set (handles.FeatSel_run_button, 'String', 'Run', 'Enable', 'on', 'UserData', []);
    set (handles.FeatSel_progress_text, 'String', 'Aborted');
end
guidata (hObject, handles);
updateGUI (handles);
if handles.debug, disp ('ok'); end





function FeatSel_methodParams_edit_Callback(hObject, eventdata, handles)
% hObject    handle to FeatSel_methodParams'_edit (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of FeatSel_methodParams'_edit as text
%        str2double(get(hObject,'String')) returns contents of FeatSel_methodParams'_edit as a double

if handles.debug, disp ('change parameters ...'); end
params = get (hObject, 'String');
ind = get (handles.FeatSel_method_popup, 'Value');
handles.selMethodParams{ind} = params;
guidata (hObject, handles);
if handles.debug, disp ('ok'); end

% --- Executes during object creation, after setting all properties.
function FeatSel_methodParams_edit_CreateFcn(hObject, eventdata, handles)
% hObject    handle to FeatSel_methodParams'_edit (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


function Class_classifierParams_edit_Callback(hObject, eventdata, handles)
% hObject    handle to Class_classifierParams_edit (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of Class_classifierParams_edit as text
%        str2double(get(hObject,'String')) returns contents of Class_classifierParams_edit as a double

if handles.debug, disp ('change parameters ...'); end
params = get (hObject, 'String');
ind = get (handles.Class_classifier_popup, 'Value');
handles.classMethodParams{ind} = params;
guidata (hObject, handles);
if handles.debug, disp ('ok'); end

% --- Executes during object creation, after setting all properties.
function Class_classifierParams_edit_CreateFcn(hObject, eventdata, handles)
% hObject    handle to Class_classifierParams_edit (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


function Class_reductionParams_edit_Callback(hObject, eventdata, handles)
% hObject    handle to Class_reductionParams_edit (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of Class_reductionParams_edit as text
%        str2double(get(hObject,'String')) returns contents of Class_reductionParams_edit as a double

if handles.debug, disp ('change parameters ...'); end
params = get (hObject, 'String');
ind = get (handles.Class_reduction_popup, 'Value');
handles.redMethodParams{ind} = params;
guidata (hObject, handles);
if handles.debug, disp ('ok'); end

% --- Executes during object creation, after setting all properties.
function Class_reductionParams_edit_CreateFcn(hObject, eventdata, handles)
% hObject    handle to Class_reductionParams_edit (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


function Class_evaluationParams_edit_Callback(hObject, eventdata, handles)
% hObject    handle to Class_evaluationParams_edit (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of Class_evaluationParams_edit as text
%        str2double(get(hObject,'String')) returns contents of Class_evaluationParams_edit as a double

if handles.debug, disp ('change parameters ...'); end
params = get (hObject, 'String');
ind = get (handles.Class_evaluation_popup, 'Value');
handles.evalMethodParams{ind} = params;
guidata (hObject, handles);
if handles.debug, disp ('ok'); end

% --- Executes during object creation, after setting all properties.
function Class_evaluationParams_edit_CreateFcn(hObject, eventdata, handles)
% hObject    handle to Class_evaluationParams_edit (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


function FeatSel_strategyParams_edit_Callback(hObject, eventdata, handles)
% hObject    handle to FeatSel_strategyParams_edit (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of FeatSel_strategyParams_edit as text
%        str2double(get(hObject,'String')) returns contents of FeatSel_strategyParams_edit as a double

if handles.debug, disp ('change parameters ...'); end
params = get (hObject, 'String');
ind = get (handles.FeatSel_strategy_popup, 'Value');
handles.selStratParams{ind} = params;
guidata (hObject, handles);
if handles.debug, disp ('ok'); end

% --- Executes during object creation, after setting all properties.
function FeatSel_strategyParams_edit_CreateFcn(hObject, eventdata, handles)
% hObject    handle to FeatSel_strategyParams_edit (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on button press in FeatSel_boxplot_button.
function FeatSel_boxplot_button_Callback(hObject, eventdata, handles)
% hObject    handle to FeatSel_boxplot_button (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

if handles.debug, disp ('prepare feature selection ...'); end
num = length (handles.featmat);
featmat = [];
for i = 1:num
    featmat = [featmat, handles.featmat{i}];
end
labels = handles.labels;
featnames = char (handles.featnames);
if handles.debug, disp ('ok'); end

if handles.debug, disp ('run FeatShow ...'); end
fset = FeatShow (featmat, featnames, labels);
if handles.debug, disp ('ok'); end

if handles.debug, disp ('update gui ...'); end
if ~ isempty (fset)
	set (handles.FeatSel_select_edit, 'String', num2str (fset'));
end
guidata (hObject, handles);
if handles.debug, disp ('ok'); end




% --- Executes on button press in Class_run_button.
function Class_run_button_Callback(hObject, eventdata, handles)
% hObject    handle to Class_run_button (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

if handles.debug, disp ('update gui ...'); end
handles.blockGUI = logical (1);
updateGUI (handles);
drawnow;
if handles.debug, disp ('ok'); end

try
    if handles.debug, disp ('prepare classification ...'); end
    cmethod = handles.classMethodFunc{get (handles.Class_classifier_popup, 'Value')};
    copt = str2num (get (handles.Class_classifierParams_edit, 'String'));
    rmethod = handles.redMethodFunc{get (handles.Class_reduction_popup, 'Value')};
    ropt = str2num (get (handles.Class_reductionParams_edit, 'String'));
    emethod = handles.evalMethodFunc{get (handles.Class_evaluation_popup, 'Value')};
    eopt = str2num (get (handles.Class_evaluationParams_edit, 'String'));
    smethod = handles.selStratFunc{get (handles.FeatSel_strategy_popup, 'Value')};
    classInfo = strvcat (['classifier: ',cmethod, ' ', mat2str(copt)], ['reduction: ', rmethod, ' ', mat2str(ropt)], ['evaluation: ', emethod, ' ',mat2str(eopt)]);
    featmat = [];
    featnames = [];
    num = length (handles.featmat);
    for i = 1:num
        featmat = [featmat, handles.featmat{i}];
        featnames = strvcat (featnames, handles.featnames{i});
    end
    fset = str2num (get (handles.FeatSel_select_edit, 'String'));
    fset (find (fset < 1 | fset > size (featmat, 2))) = [];
    if ~ isempty (fset)
        featmat = featmat(:,fset);
        featnames = featnames(fset,:);
    end
    labels = handles.labels;
    if handles.debug, disp ('ok'); end
    if handles.debug, disp ('run classification ...'); disp (classInfo); end
    [p pc cm] = aubt_classifier (featmat, labels, cmethod, copt, rmethod, ropt, emethod, eopt);
    if handles.debug, disp ('ok'); end
    
    if handles.debug, disp ('show results ...'); end
        results = {p, pc, cm};
        ResultShow (classInfo, featnames, handles.labelnames, results);
    if handles.debug, disp ('ok'); end
catch
    if handles.debug, err = lasterror(); err.message, end
    Error ();
end

if handles.debug, disp ('update gui ...'); end
handles.blockGUI = logical (0);
guidata (hObject, handles);
updateGUI (handles);
if handles.debug, disp ('ok'); end




% --- Executes on button press in AuBTgui_about_button.
function AuBTgui_about_button_Callback(hObject, eventdata, handles)
% hObject    handle to AuBTgui_about_button (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

AboutShow;


% --- Executes on button press in AuBTgui_exit_button.
function AuBTgui_exit_button_Callback(hObject, eventdata, handles)
% hObject    handle to AuBTgui_exit_button (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

close;


% % --- Executes on button press in AuBTgui_help_button.
% function AuBTgui_help_button_Callback(hObject, eventdata, handles)
% % hObject    handle to AuBTgui_help_button (see GCBO)
% % eventdata  reserved - to be defined in a future version of MATLAB
% % handles    structure with handles and user data (see GUIDATA)
% 
% open ([handles.rpath,filesep,'doc',filesep','AubTGuide.pdf']);



% --- Executes on button press in combiFeat_fisherPlot_button.
function combiFeat_fisherPlot_button_Callback(hObject, eventdata, handles)
% hObject    handle to combiFeat_fisherPlot_button (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

if handles.debug, disp ('prepare fisher plot ...'); end
num = length (handles.featmat);
featmat = [];
for i = 1:num
    featmat = [featmat, handles.featmat{i}];
end
fset = str2num (get (handles.FeatSel_select_edit, 'String'));
if ~ isempty (fset)
    featmat = featmat(:,fset);
end
labels = handles.labels;
labelnames = handles.labelnames;
colors = lines;
colors = colors (1:max(labels), :);
if handles.debug, disp ('run RecShow ...'); end
RecShow (featmat, labelnames, labels, colors);
if handles.debug, disp ('ok'); end